/*
在javaScript中是没有枚举的概念的TS帮我们定义了枚举这个类型

使用枚举 通过enum关键字定义我们的枚举
*/
// 1.数字枚举
// 之前旧的用例
const enumeFn = (type) => {
    if (type === 'red') {
        return 0;
    }
    if (type === 'green') {
        return 1;
    }
    if (type === 'blue') {
        return 2;
    }
};
let enumeObj = {
    'red': 0,
    'green': 1,
    'blue': 2
};
// 新的用例
var Color;
(function (Color) {
    Color[Color["red"] = 0] = "red";
    Color[Color["green"] = 1] = "green";
    Color[Color["blue"] = 2] = "blue";
})(Color || (Color = {}));
console.log(Color['red']);
console.log(Color['green']);
console.log(Color['blue']);
// 增长枚举（仅适用于数字枚举）
var Color02;
(function (Color02) {
    Color02[Color02["red"] = 1] = "red";
    Color02[Color02["green"] = 2] = "green";
    Color02[Color02["blue"] = 3] = "blue";
})(Color02 || (Color02 = {}));
console.log(Color02['red']);
console.log(Color02['green']);
console.log(Color02['blue']);
// 2.字符串枚举
/*
应用场景是：属性的可读性
*/
var Color03;
(function (Color03) {
    Color03["yellow"] = "yellow";
    Color03["pink"] = "pink";
    Color03["white"] = "white";
})(Color03 || (Color03 = {}));
console.log(Color03['yellow']);
console.log(Color03['pink']);
console.log(Color03['white']);
// 3.异构枚举
/*
枚举可以混合字符串和数字成员
*/
var dicState;
(function (dicState) {
    dicState[dicState["yes"] = 1] = "yes";
    dicState["no"] = "false";
})(dicState || (dicState = {}));
console.log(dicState['yes']);
console.log(dicState['no']);
let enumObj = {
    red: dicState.yes
};
let resCodeValue = 0;
if (resCodeValue === 0 /* resCode.success */) {
    console.log('请求成功');
}
// 6.反向映射
/*
它包含了正向映射（ name -> value）和反向映射（ value -> name）

要注意的是 不会为字符串枚举成员生成反向映射。
*/
var resCode02;
(function (resCode02) {
    resCode02[resCode02["success"] = 0] = "success";
    resCode02[resCode02["error"] = 1] = "error";
})(resCode02 || (resCode02 = {}));
let successCode = resCode02.success;
console.log(successCode);
let key = resCode02[successCode];
console.log(key);
